package edu.zut.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 如何动态解析url：http://localhost:8080/Web207_208/showInfo   get
 * HttpServletRequest: http请求对象 url就属于请求中的一部分，解析url，本质上就是解析请求中的某些信息
 * HttpServletResponse:http响应对象
 */
public class ShowInfoServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //利用request对象解析url
        //uri、contextPath 属于url里面的环境路劲
        StringBuffer url = request.getRequestURL();
        System.out.println("url = " + url);
        String uri = request.getRequestURI();
        System.out.println("uri = " + uri);
        String contextPath = request.getContextPath();
        System.out.println("contextPath = " + contextPath);
        //请求资源路劲
        String servletPath = request.getServletPath();
        System.out.println("servletPath = " + servletPath);
        //资源路劲的路劲信息
        String pathInfo = request.getPathInfo();
        System.out.println("pathInfo = " + pathInfo);
        //获取请求方式
        String method = request.getMethod();
        System.out.println("method = " + method);

    }
}
